<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">
        <i class="el-icon-s-promotion"></i> 后台管理
      </el-breadcrumb-item>
      <el-breadcrumb-item>属性模板列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-divider></el-divider>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="80" align="center"></el-table-column>
      <el-table-column prop="name" label="名称" width="230" header-align="center"></el-table-column>
      <el-table-column prop="pinyin" label="拼音" width="230" header-align="center"></el-table-column>
      <el-table-column prop="keywords" label="关键词列表" header-align="center"></el-table-column>
      <el-table-column prop="sort" label="排序序号" width="100" align="center"></el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle size="mini"
                     @click="openEditDialog(scope.row)"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle size="mini"
                     @click="openDeleteConfirm(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: []
    }
  },
  methods: {
    openDeleteConfirm(attributeTemplate){
      let message = '此操作将永久删除【' + attributeTemplate.name + '】品牌，是否继续？';
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(attributeTemplate);
      }).catch(() => {
      });
    },
    handleDelete(attributeTemplate){
      let url = 'http://localhost:9080/attribute-templates/'+ attributeTemplate.id +'/delete';
      console.log("url: " + url);

      this.axios.post(url, formData).then((response) => {
        let responseBody = response.data;
        if(responseBody.state == 20000){
          this.loadBrandList();
        }else{
          this.$alert(responseBody.message, '操作失败', {
            confirmButtonText: '确定',
            callback: action => {
              this.loadBrandList();
            }
          });
        }
      });
    },
    loadBrandList(){
      let url = 'http://localhost:9080/attribute-templates';
      console.log('url: '+url);

      this.axios.get(url).then((response) => {
        let responseBody = response.data;
        this.tableData = responseBody.data;
      });
    }
  },
  mounted(){
    this.loadBrandList();
  }
}
</script>

<style scoped>

</style>